/*
webim
*/
var imSocket = {
	swfPath: 'swf/socket.swf',
	port: 6666,
	host: '192.168.0.7',
	autoReconnect: 10000, //断线后自动重连的时间 
	contentInterval: 500, //每次连接失败后重新再连的时间间隔
	connectMaxTime: 10, //最大重连次数为2次
	connectedTime: 0, //已经连接次数
	init: function(onData, onConCallBack){
		this.appendSocket();
		this.onData = onData; //收到数据后的处理函数
		this.onConCallBack = onConCallBack; //连接服务器后的处理函数
		this.connect();
	},

	connect: function(){
		if ('function' == typeof(window.document.socket.connect)){
			this.connectedTime++; //已连接次数加1 debug("连接服务器" + this.host + ":" + this.port + "，请稍候...");
			window.document.socket.SetVariable("host", this.host);
			window.document.socket.SetVariable("port", this.port);
			window.document.socket.connect();
		}else{
			window.setTimeout(this.connect.bind(this), this.contentInterval);
		}
	},

	close: function(){
		window.document.socket.close();
	},

	appendSocket: function(){
		var swfHtml = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="0" height="0" id="socket" align="middle">'
					+'<param name="allowScriptAccess" value="sameDomain" />'
					+'<param name="allowFullScreen" value="false" />'
					+'<param name="movie" value="' + this.swfPath + '?rand='+ Math.random() +'" />'
					+'<param name="allowNetworking" value="all" />'
					+'<embed src="' + this.swfPath + '?rand=' + Math.random() + '" width="0" height="0" name="socket" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" allowNetworking="all" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
					+'</object>';
		var swfDiv = document.createElement('div');
		document.body.appendChild(swfDiv);
		swfDiv.innerHTML = swfHtml;
	},

	send: function(data){ //发送数据
		window.document.socket.SetVariable("data", data);
		window.document.socket.send();
		//debug('sendData = ' + data);
	},

	onConnect: function(reData){
		//debug(reData);
		if (true == reData){
			debug("连接服务器成功");
			this.onConCallBack(); //连接后的回调函数
		}else{
			if (this.connectedTime >= this.connectMaxTime)	return debug('超过最大重连次数'); //已经达到最大的连接数
			debug('连接服务器不成功,准备重连');
			this.connect(); //重新连接
		}
	},

	onClose : function() {
		setTimeout(this.connect.bind(this), this.autoReconnect);
	}
};

var webIm = {
	apps: [imLog, imCamera, imInfo], //聊天窗口上部的应用
	tools: [imFont, imEmote],  //聊天窗口中间的工具
	windowCssNameSpace: 'im_window',
	imCssNameSpace: 'im',
	chatWidth: 400, //聊天窗口宽度
	chatLength: 50, //窗口保存聊天记录数
	imclass: [], //分类
	buddies: [], //好友
	groups: [], //群
	chatings: [], //正在和我聊天的用户
	nickName: null,
	privateKey: null,
	isSending: false, //是否正在发送
	dataPool: [], //待发送数据池
	isJoin: false, //是否加入聊天服务器
	init: function(imData){ //imData为服务器返回的json对象
        if (true == this.isInit)	return; //防止多次加载14:01
		mainDiv = dom.newNode('div', {'class':this.imCssNameSpace});
		mainDiv.appendChild(this.makeUserInfo(imData.userinfo));
		this.bodyDiv = dom.newNode('div', {'class':'im_body'});
		this.appendClass(imData.imclass);
		this.appendBuddy(imData.buddies);
		this.appendGroup(imData.groups);
		mainDiv.appendChild(this.bodyDiv);
		var imWindow = new publicWindow(mainDiv, 'web im', 193, 100); //指定窗口的位置为left:100
		imWindow.cssNameSpace = this.windowCssNameSpace;
		imWindow.minWidth = 150; //最小宽度
		imWindow.minHeight = 150; //最小高度
		imWindow.reHeight = this.reHeight.bind(this); //重构reHeight方法
		imWindow.canMax = false;
		imWindow.canClose = false;
		imWindow.init(); //显示窗口
		imSocket.init(this.parseData.bind(this), this.getKey.bind(this)); //连接socket
		closeSelect(this.bodyDiv);//禁止选取
		this.tagHeight = this.currentTag.nextSibling.offsetHeight;
		if ( this.tagHeight > 500){
			this.currentTag.nextSibling.style.height = '500px';
			this.tagHeight = 500;
		}
		this.shiftHeight = 0; //高度偏移
		this.isInit = true;
	},

	pushToPool: function(data){
		this.dataPool.push(data);
	},

	sendWithKey: function(data){
		data = this.privateKey + '|' +data;
		this.privateKey = null;
		imSocket.send(data);
	},

	send: function(){
		//debug('isJoin:' + this.isJoin + ', privateKey' + this.privateKey + ',isSending'+ this.isSending);
		if (false == this.isJoin)	return; //还没有加入聊天服务器
		var data = arguments[0];
		if (!this.privateKey)	this.pushToPool(data); //没有key加入dataPool
		var phpKey = arguments[1];
		if (true == this.isSending){
			if (phpKey && 32 == phpKey.length){
				this.sendWithKey(data);
			}else{
				this.pushToPool(data);
			}
		}else if ('function' == typeof(this.sendHandle)){
			this.isSending = true;
			this.sendHandle(data);
		}else{
			this.isSending = true;
			this.sendWithKey(data);
		}
	},
	
	updatePrivateKey: function(nickName, key){
		if (nickName != this.nickName)	return;
		this.privateKey = key; //更新privateKey
		this.isSending = false; //消息发送成功
		//debug('update private key success');
	},

	getKey: function(){
		imSocket.send('G');
	},

	joinServer: function(re){
		var phpKey = parseJson(re)['key'];
		imSocket.send(this.privateKey + '|J|' + this.nickName + '|' + phpKey);
	},

	joinGroup: function(){
		//debug('加入组'+'1 == '+(this.groupLen));
		if (0 == this.groupLen--)	return this.isJoin = true;
		imSocket.send(this.privateKey + '|P|' + this.groups[this.groupLen].nickName + '|X');
		//debug(this.groups(this.groupLen));
	},

	parseData: function(data){
		debug('收到消息=>'+data);
		var arr = data.split('|');
		if ("" == data)	return;	
		switch(arr[1]){
			case 'G':
				//debug('get private key success')
				this.updatePrivateKey(this.nickName, arr[0]);
				ajax.get('getkey.php?data=' + this.nickName, this.joinServer.bind(this));
			break;
			case 'J':
			case 'P':
				this.updatePrivateKey(this.nickName, arr[0]);
				this.joinGroup();
			break;
			case "C":
				this.updatePrivateKey(arr[2], arr[0]);
				this.dispatchMessage('C', arr[2], arr[3], arr[4]);
			break;
			case 'M':
				this.updatePrivateKey(arr[2], arr[0]);
				this.dispatchMessage('M', arr[2], arr[3]);
			break;
		}
	},

	appendClass: function(imclass){
		this.classTag = this.makeTag('好友列表');
		imclass.push({'clsid':-1, 'grpname':'陌生人'}); //默认用户组
		for (var i = 0; i < imclass.length; i++){
			var newClass = new imClass(imclass[i].clsid, imclass[i].grpname);
			newClass.init();
			this.classTag.tagDiv.appendChild(newClass.imclassDiv);
			this.imclass.push(newClass);
		}
		dom.removeClass(this.classTag.tagDiv, 'hide'); //显示标签内容
		this.currentTag = this.classTag.tagTitle; //正在使用的标签
	},
	
	appendBuddy: function(buddies){
		var isFoundimclass = false;
		for (var i = buddies.length - 1; i >= 0; i--){
			var newBud = new imBuddy(buddies[i]);
			this.buddies.push(newBud);
			newBud.init();
			this.addToClass(newBud, buddies[i].clsid);
		}
	},
	
	reHeight: function(my){
		this.tagHeight += my;
		this.setTagHeight();
	},

	addToClass: function(newBud, classId){
		isFoundimclass = false;
		for (var j = this.imclass.length - 1; j >= 0; j--){
			if (this.imclass[j].imclassId == classId){
				isFoundimclass = this.imclass[j];
				break;
			}
		}
		if (false != isFoundimclass){ //找到属于某个组
			newBud.classObj = isFoundimclass
			isFoundimclass.appendBuddy(newBud);
		}else
			debug('no imclass');
	},

	appendGroup: function(groups){
		if (0 == groups.length)	return; //没有加入任何群
		this.groupTag = this.makeTag('群');
		for (var i = 0; i < groups.length; i++){
			var grp = new imGroup(groups[i].gname);
			grp.init();
			this.groupTag.tagDiv.appendChild(grp.buddyDiv);
			this.groups.push(grp);
		}
		this.groupLen = this.groups.length; //加入聊天服务器时要用
	},

	makeUserInfo: function(userInfo){
		this.nickName = userInfo.nkname;
		this.userStatus = userInfo.status;
		this.avatar = dom.newNode('img', {'width':40, 'height':40, 'src':userInfo.avatar});
		this.statusDiv = dom.newNode('div', {'class':'status'});
		var infoDiv = dom.makeHtml(
			['div', {'class':'userinfo bg'}, 
				['div', {'class':'avatar'}, this.avatar],
				['div', {'class':'detail'},
					['div', {}, userInfo.nkname],
					this.statusDiv
				],
				['div', {'class':'clear'}] //clear
			]);
		this.setStatus();
		return infoDiv;
	},

	switchTag: function(e){
		var obj = e.srcElement || e.target;
		while (obj.className != 'tag')	obj = obj.parentNode; //如果点到span上，事件源不是div
		if (obj == this.currentTag)	return; //就是正在使用的tag
		dom.addClass(this.currentTag.nextSibling, 'hide');
		dom.removeClass(obj.nextSibling, 'hide');
		this.currentTag = obj;
		this.setTagHeight();
	},

	setTagHeight: function(){
		this.currentTag.nextSibling.style.height = this.tagHeight + 'px';
	},

	makeTag: function(tName){
		var t = new imTag(tName);
		t.init();
		eve.observe(t.tagTitle, 'click', this.switchTag, this);
		return t;
	},

	setStatus: function(){
		if (1 == this.userStatus)
			this.statusDiv.innerHTML = '在线';
		else if(2 == this.userStatus)
			this.statusDiv.innerHTML = '忙碌';
	},

	dispatchMessage: function(){
		if (arguments[1] == this.nickName)	return; //是自己的消息
		switch(arguments[0]){
			case 'M':
				//debug('我是=>'+this.nickName+'，消息来自=>'+ nickName);		
				this.showPrivateMessage(arguments[1], arguments[2]);
			break;
			case 'C':
				this.showGroupMessage(arguments[1], arguments[2], arguments[3]);
			break;
		}
	},
	
	showPrivateMessage: function(nickName, content){
		for (var i = this.chatings.length - 1; i >= 0; i--){
			if (this.chatings[i].nickName == nickName)	return this.chatings[i].newMessage(content); //在打开的聊天窗口中
		}
		for (i = this.buddies.length - 1; i >= 0; i--){
			if (this.buddies[i].nickName == nickName)	return this.buddies[i].newMessage(content); //是自己的好友
		}
		this.strangerMessage(nickName, content); //陌生人的消息
	},

	strangerMessage: function(nickName, content){
		var newBud = new imBuddy({'nkname':nickName, 'clsid':-1, 'ico':'icon/im/online.gif', 'online':1});
		this.buddies.push(newBud);
		newBud.init();
		this.addToClass(newBud, -1); //-1表示陌生人
		newBud.newMessage(content);
	},
	
	showGroupMessage: function(nickName, groupName, content){ //nickName是消息发出者的nickName
		for (i = this.groups.length - 1; i >= 0; i--){
			if (groupName == this.groups[i].nickName)	return this.groups[i].newMessage(nickName, content);
		}
	}
}

function imTag(imtagName){
	this.tagTitle = dom.newNode('div', {'class':'tag'});
	dom.newNode('div', {'class':'tag_icon'}, this.tagTitle);
	var tagSpan = dom.newNode('span', {}, this.tagTitle);
	tagSpan.innerHTML = imtagName;
	this.flashImg = []; //闪动的图片
}

imTag.prototype = {
	currentFlash: false,
	init: function(){
		this.tagDiv = dom.newNode('div', {'class':'tag_div hide'});
		webIm.bodyDiv.appendChild(this.tagTitle);
		webIm.bodyDiv.appendChild(this.tagDiv);
	},
	
	flashTitle: function(obj){
		this.flashImg.push(obj);
		this.getFlashImg();
	},
	
	removeFlashImg: function(sign){ //传入nickName停止头像闪动
		if (sign == this.currentFlash)	return this.currentFlash = false; //是当前正在闪动的头像
		for (var i = this.flashImg.length - 1; i >= 0; i--){
			if (this.flashImg[i].sign == sign){
				delete(this.flashImg[i]);
				return;
			}
		}
	},

	getFlashImg: function(){
		if (true == this.isFlash)	return;
		if (0 == this.flashImg.length)	return;
		var flashObj = this.flashImg.shift();
		var img = flashObj['img'];
		this.currentFlash = flashObj['sign'];
		try{
			img.style.visibility = null;
		}catch (e){
			img.style.visibility = '';
		}
		this.tagTitle.firstChild.appendChild(img);
		this.doFlashTitle('visible');
		this.isFlash = true;
	},

	doFlashTitle: function(isVisible){
		if (false == this.currentFlash){
			this.tagTitle.firstChild.innerHTML = '';
			return this.isFlash = false;
		}
		isVisible = ('visible' == isVisible) ? 'hidden' : 'visible';
		this.tagTitle.firstChild.style.visibility = isVisible;
		setTimeout(function(){this.doFlashTitle(isVisible);}.bind(this), 500);
	}
};

function imClass(imclassId, imclassName){
	this.imclassId = imclassId;
	this.imclassName = imclassName;
	this.buddies = []; //好友统计
	this.isOpen = true;
} //好友好组类;
imClass.prototype = {
	init: function(){
		this.imclassDiv = dom.newNode('div');
		this.buddyTotal = dom.newNode('span',{'class':'buddy_total'});
		this.titleDiv = dom.makeHtml(['div', {'class':'imclass_title'}, ['span', {}, this.imclassName], this.buddyTotal]);
		dom.appendNodes(this.imclassDiv, this.titleDiv, dom.newNode('div', {'class':'imclass_buddies'}));
		eve.observe(this.titleDiv, 'click', this.clickTitle, this);
	},

	clickTitle: function(){
		if (true == this.isOpen){
			dom.addClass(this.titleDiv, 'imclass_title_hide');
			dom.addClass(this.imclassDiv.lastChild, 'hide');
			this.isOpen = false;
		}else{
			dom.removeClass(this.titleDiv, 'imclass_title_hide');
			dom.removeClass(this.imclassDiv.lastChild, 'hide');
			this.isOpen = true;
		}
	},

	appendBuddy: function(buddy){
		this.buddies.push(buddy);
		this.imclassDiv.lastChild.appendChild(buddy.buddyDiv);
		this.countTotal();
	},
	
	countTotal: function(){
		var online = 0;
		for (var i = this.buddies.length - 1; i >= 0; i--){
			if (1 == this.buddies[i].online)	online++;
		}
		this.buddyTotal.innerHTML = '('+ online + '/' +this.buddies.length+ ')';
	},
	
	flashTitle: function(isVisible){
		if (true == this.isOpen)	return this.titleDiv.firstChild.style.visibility = 'visible';
		if ('undefined' == typeof(isVisible))	isVisible = 'visible';
		isVisible = ('visible' == isVisible) ? 'hidden' : 'visible';
		this.titleDiv.firstChild.style.visibility = isVisible;
		setTimeout(function(){this.flashTitle(isVisible);}.bind(this), 500);
	}
};

function imUser(){} //用户基类
imUser.prototype = {
	isChat: false, //是否已经打开聊天窗口
	userCss: 'buddy_row',
	init: function(){
		this.buddyDiv = dom.makeHtml(['div', {'class':this.userCss}, this.statusDiv, ['span', {'class':'label'}, this.nickName]]);
		dom.roleMouseOver(this.buddyDiv, this.userCss + '_over');
		eve.observe(this.buddyDiv, 'dblclick', this.openChatWindow, this);
		this.setOnlineStatus();
	},
	
	setOnlineStatus: function(){},
	
	flashHead: function(isVisible){
		if ('undefined' == typeof(isVisible)){ //第一次调用
			if (true == this.isFlashHead)	return;
			isVisible = 'hidden';
		}
		if (true == this.isChat){
			this.isFlashHead = false;
			return this.statusDiv.style.visibility = 'visible';
		}
		if (!this.isFlashHead)	this.isFlashHead = true;
		isVisible = ('hidden' == isVisible) ? 'visible' : 'hidden';
		this.statusDiv.style.visibility = isVisible;
		setTimeout(function(){this.flashHead(isVisible);}.bind(this), 500);
	}
};

function imBuddy(buddy){
	this.online = buddy.online;
	this.statusDiv = dom.newNode('div', {'class':'buddy_head'});
	this.statusDiv.style.backgroundImage = 'url('+ buddy.ico +')';
	this.nickName = buddy.nkname;
	this.messagePool = [];
}
objectExtend(imBuddy, imUser, { //继承imUser
	userCss: 'buddy_row',
	newMessage: function(message){
		//debug('buddy group user');
		var messageObj = parseJson(message);
		messageObj.time = makeChatTime();
		if (true == this.isChat)
			this.chatWindow.newMessage(messageObj, this.nickName);
		else{
			webIm.classTag.flashTitle({'img':this.statusDiv.cloneNode(this.statusDiv), 'sign':this.nickName}); //sign是闪动标志的区分
			this.flashHead(); //闪动头像,表示有新消息
			this.messagePool.push({'msg':messageObj, 'nkname': this.nickName});
			this.classObj.flashTitle();
		}
	},
	
	openChatWindow: function(){
		if (true == this.isChat)
			this.chatWindow.setFocus();
		else{
			this.chatWindow = new imChat(this);
			webIm.classTag.removeFlashImg(this.nickName);
			this.isChat = true;
			this.chatWindow.init();
			webIm.chatings.push(this); //加入正在聊天的列表中
		}
	},
	
	setOnlineStatus: function(){
	if (0 == this.online)	this.statusDiv.style.backgroundImage = "url('icon/im/offline.gif')";
	}
});

function groupUser(user){ //群用户类 群里有的用户可能是自己的好友
	this.online = user.online;
	this.statusDiv = dom.newNode('div', {'class':'buddy_head'});
	this.statusDiv.style.backgroundImage = 'url('+ user.ico +')';
	this.nickName = user.nkname;
}
objectExtend(groupUser, imUser, {
	userCss: 'group_user',
	openChatWindow: function(){
		if (true == this.isChat)
			this.chatWindow.setFocus();
		else{
			for (var i = webIm.buddies.length - 1; i >= 0; i--){
				if (webIm.buddies[i].nickName == this.nickName)	return webIm.buddies[i].openChatWindow(); //该用户是自己的好友
			}
			for (var i = webIm.chatings.length - 1; i >= 0; i--){
				if (webIm.chatings[i].nickName == this.nickName)	return webIm.chatings[i].chatWindow.setFocus(); //不是我的好友,但正在和我聊天
			}
			this.chatWindow = new imChat(this);
			this.chatWindow.init();
			this.isChat = true;
			webIm.chatings.push(this);
		}
	}
});

function imGroup(groupName){
	this.statusDiv = dom.newNode('div', {'class':'buddy_group_icon'});
	this.nickName = groupName;
	this.messagePool = [];
}
objectExtend(imGroup, imUser, {
	openChatWindow: function(){
		if (true == this.isChat)
			this.chatWindow.setFocus();
		else{
			this.chatWindow = new imGroupChat(this);
			this.chatWindow.init();
			this.isChat = true;
			webIm.groupTag.removeFlashImg(this.nickName);
		}
	},

	newMessage: function(nickName, message){
		var messageObj = parseJson(message);
		messageObj.time = makeChatTime();
		if (true == this.isChat)
			this.chatWindow.newMessage(messageObj, nickName);
		else{
			//debug('flash title');
			webIm.groupTag.flashTitle({'img':this.statusDiv.cloneNode(this.statusDiv), 'sign':this.nickName}); //this.nickName 是groupName
			this.flashHead(); //闪动头像,表示有新消息
			this.messagePool.push({'msg':messageObj, 'nkname': nickName});
		}
	}
});

function imChat(buddy){
	this.chatWith = buddy; //this.chatWith是聊天对象 包括 好友,陌生人,群
	this.apps = []; //窗口顶部的功能应用
	this.tools = []; //窗口中部的小工具
	this.userStyle = {}; //用户自定义样式
}
imChat.prototype = {
	currentTool: false, //当前展开的工具
	sendMethod: 1, //按ctrl + enter 键发送消息
	sendMethodDiv: false,
	cursorPosition: 0, //光标位置
	init: function(){
		this.chatDiv = dom.newNode('div', {'class':webIm.imCssNameSpace});
		this.appendAppBar();
		this.appendMessageDiv();
		this.appendToolBar();
		this.appendSendBox();
		this.chatWindow = new publicWindow(this.chatDiv, '与' + this.chatWith.nickName + '聊天中', webIm.chatWidth);
		this.appendButtonBar();
		this.chatWindow.cssNameSpace = webIm.windowCssNameSpace; //风格
		this.chatWindow.minHeight = 200;
		this.chatWindow.minWidth = webIm.chatWidth - 100;
		this.chatWindow.reHeight = this.reHeight.bind(this);
		this.chatWindow.closeCallBack = this.closeCallBack.bind(this); //设置关闭窗口时的回调函数
		this.chatWindow.init();
		eve.observe(this.chatWindow.windowDiv, 'mousedown', this.closeCurrentTool, this); //点击messageDiv, fontDiv, sendBox, buttonDiv时,关闭正打开的tool
		eve.observe(this.sendBox, 'keydown', this.checkKeyCode, this);
		if (browser.ie){
			this.rang = document.selection.createRange();
			eve.observe(this.sendBox, 'keyup', this.getRang, this);
			eve.observe(this.sendBox, 'click', this.getRang, this);
		}
		this.messageDiv.style.height ='200px'; //聊天窗口默认高度
		this.showMessagePool(); //加载未显示的聊天记录
		this.sendBox.focus();
	},

	showMessagePool: function(){
		for (var i = 0; i < this.chatWith.messagePool.length; i++){
			this.appendMessage(this.chatWith.messagePool[i]['msg'], this.chatWith.messagePool[i]['nkname']);
		}
		this.chatWith.messagePool = []; //清空未显示消息缓存
	},

	getRang: function(){ //保存光标的位置
		this.rang = document.selection.createRange();
	},

	setCursorPosition: function(){
		this.sendBox.select();
		this.rang.setEndPoint("StartToStart", document.selection.createRange());
		this.rang.collapse(false);
		this.rang.select();
	},

	closeCurrentTool: function(){
		if (false == this.currentTool || true == this.isToolClosing)	return;
		dom.hide(this.currentTool);
		this.currentTool = false;
		this.sendBox.focus();
		if (browser.ie)	this.setCursorPosition();
	},

	checkKeyCode: function(e){
		var key = e.keyCode || e.which;
		if(13 != key)	return;
		if((1 == imChat.prototype.sendMethod && e.ctrlKey) || (0 == imChat.prototype.sendMethod && !e.ctrlKey)){
			this.sendMessage();
			return false;
		}else if(e.ctrlKey && 0 == imChat.prototype.sendMethod){
			this.enter();
		}
	},

	enter: function(){ //当发送方式为0,按下Ctrl+enter键时回车效果.
		if(browser.ie)
			this.insertValue('\r');//加入换行符
		else
			this.insertValue('\n');
	},

	newMessage: function(messageObj, nickName){
		this.appendMessage(messageObj, nickName);
		this.chatWindow.flashTitle('新消息');
	},

	sendMessage: function(){
		if (false == webIm.jsJoin)	return this.showErr('正在加入聊天服务器,请稍等');
		var content = this.sendBox.value;
		content = filterContent(content);
		var utc = Date.parse(new Date)/1000; //将时间转换成数字
		if (utc - this.sendTime < webIm.minPeriod)	return this.showErr('请不要频率发送消息');
		if('' == content)	return this.showErr('发送内容不能为空');
		this.sendTime = utc;
		var jsonObj = {'c':content};
		for (p in this.userStyle){
			jsonObj['s'] = this.userStyle; //加入样式
			break;
		}
		var jsonStr = postParam(jsonObj);
		jsonStr = encodeHtml(jsonStr); //编码
		if (jsonStr>950)	return this.showErr('报歉，聊天内容不能太长。');
		jsonObj.time = makeChatTime();
		this.appendMessage(jsonObj, webIm.nickName); //'me'表示是自己的消息
		this.sendBox.value = '';
		this.sendBox.focus();
		webIm.send(this.packMessage(jsonStr));
	},

	packMessage: function(jsonStr){
		return 'M|' + this.chatWith.nickName + '|'+jsonStr;
	},

	appendMessage: function(chatObj, nickName){
		var content = decodeHtml(chatObj.c);
		var msgDiv = dom.newNode('div', {'class':'msg_div'});
		msgDiv.innerHTML = content;
		if (chatObj.s){ //有样式
			for (var s in chatObj.s){
				msgDiv.style[s] = chatObj['s'][s];
			}
		}
		var showCss = (webIm.nickName == nickName)? 'me' : 'him';
		if (this.listLen++ > webIm.chatLength) dom.removeNodes(this.msgList.firstChild); //如果聊天记录数已经超过设置条数，删除第一条
		this.messageDiv.appendChild(dom.makeHtml(['div', {}, ['div',{'class':showCss}, nickName + ' ', chatObj.time], msgDiv]));
		setTimeout(function(){this.messageDiv.scrollTop = this.messageDiv.scrollHeight - this.messageDiv.offsetHeight;}.bind(this), 200);
	},

	showTool: function(toolObj, obj, upOrDown){ //显示工具的界面(非工具面板)
		if (this.currentTool == toolObj)	return this.closeCurrentTool();
		if (false != this.currentTool)	this.closeCurrentTool();
		dom.show(toolObj); //显示出来
		var pos = getPosition(obj, this.chatWindow.windowDiv);
		toolObj.style.top = pos[0] + ((0 == upOrDown) ? obj.offsetHeight : -toolObj.offsetHeight) + 1 + 'px';
		toolObj.style.left = pos[1] + 'px';
		toolObj.style.zIndex = parseInt(this.chatWindow.windowDiv.style.zIndex) + 1;
		this.currentTool = toolObj;
	},

	setFocus: function(){
		this.chatWindow.setFocus(); //如果聊天窗口已经打开.该窗口置顶
	},
	
	insertValue: function(str){ //在消息框内增加内容
		if(browser.ie){
			this.setCursorPosition(); //设置光标位置
			this.rang.duplicate().text = str;
		}else{
			var cursorStart = this.sendBox.selectionStart;//光标开始
			var cursorEnd = this.sendBox.selectionEnd;//光标结束
			var tmpValue = this.sendBox.value;
			this.sendBox.value = tmpValue.substr(0, cursorStart) + str + tmpValue.substr(cursorEnd); 
			this.sendBox.selectionEnd = this.sendBox.selectionStart = cursorStart + str.length; //重置光标的位置
		}
	},

	showSendMethod: function(e){
		var obj = e.srcElement || e.target;
		if (false != this.sendMethodDiv)	dom.removeNodes(this.sendMethodDiv); //如果有了,先去掉.因为sendMethod是全局的,其它窗口可能会改变sendMethod
		this.sendMethodDiv = this.createSendMethodDiv();
		this.showTool(this.sendMethodDiv, obj, 1);
	},

	createSendMethodDiv: function(){
		var sendDiv = dom.newNode('div', {'class':'option_list'}, this.chatDiv);
		var method_1 = dom.makeHtml(['div', {'class':'item'+((0 == imChat.prototype.sendMethod) ? ' item_sele' : '')}, '按Enter键发送消息']);
		var method_2 = dom.makeHtml(['div', {'class':'item'+((1 == imChat.prototype.sendMethod) ? ' item_sele' : '')}, '按Ctrl+Enter键发送消息']);
		dom.roleMouseOver(method_1, 'item_over');
		dom.roleMouseOver(method_2, 'item_over');
		method_1.val = 0;
		method_2.val = 1;
		eve.observe(method_1, 'mousedown', this.setSendMethod, this);
		eve.observe(method_2, 'mousedown', this.setSendMethod, this);
		sendDiv.appendChild(method_1);
		sendDiv.appendChild(method_2);
		return sendDiv;
	},

	setRightDivHeight: function(){ //设置聊天窗口右边窗口的高度.目前只有群聊时才有
		return;
	},

	setSendMethod: function(e){ //设置发送消息的快捷方式
		var obj = e.srcElement || e.target;
		imChat.prototype.sendMethod = obj.val;
		this.closeCurrentTool();
		resetList(this.sendMethodDiv, obj);
	},

	/*reBuildWindow: function(){ //重构窗口的最大化和还原事件
		var oldMaxWindow = this.chatWindow.maxWindow.bind(this.chatWindow);
		this.chatWindow.maxWindow = function(){ //窗口最大化时重新计算聊天界面大小
			oldMaxWindow();
			var newHeight = this.chatWindow.contentDiv.offsetHeight;
			this.msgDivHeight = this.messageDiv.offsetHeight - 2; // -2是减边框高度
			this.messageDiv.style.height = this.msgDivHeight + newHeight - this.chatWindow.height + 'px';
			this.setRightDivHeight();
		}.bind(this);
		var oldNormalWindow = this.chatWindow.normalWindow.bind(this.chatWindow);
		this.chatWindow.normalWindow = function(){ //窗口还原时,重新计算聊天界面大小
			if (this.msgDivHeight)	this.messageDiv.style.height = this.msgDivHeight + 'px'; //只有从最大化恢复窗口才会有this.msgDivHeight
			oldNormalWindow();
			this.messageDiv.scrollTop = this.messageDiv.scrollHeight - this.messageDiv.offsetHeight;
			this.setRightDivHeight();
		}.bind(this);
	},*/

	reHeight: function(my){
		var tmpHeight = parseInt(this.messageDiv.style.height) + my; //-2是减边框高度
		this.messageDiv.style.height = tmpHeight + 'px';
	},
	
	closeCallBack: function(){ //关闭窗口时的回调函数
		this.chatWindow = null;
		this.chatWith.isChat = false;
		this.chatWith.chatWindow = null;
		this.currentTool = null;
		this.chatWith = null;
		this.cleanTools();
		die(this);
	},
	
	cleanTools: function(){
		for (var i = this.apps.length - 1; i >= 0; i--)	die(this.apps[i]);
		for (i = this.tools.length - 1; i >= 0; i--)	die(this.tools[i]);
	},

	appendAppBar: function(){
		var appDiv = dom.newNode('div', {'class':'bg app_div'}, this.chatDiv);
		for (var i = 0; i < webIm.apps.length; i++){
			var app = new webIm.apps[i](this);
			this.apps.push(app);
			appDiv.appendChild(app.init());
		}
		dom.newNode('div', {'class':'clear'}, appDiv);
	},

	appendMessageDiv: function(){
		this.messageDiv = dom.newNode('div', {'class':'message_div'}, this.chatDiv);
	},
	
	appendToolBar: function(){
		var toolDiv = dom.newNode('div', {'class':'bg tool_div'}, this.chatDiv);
		for (var i = 0; i < webIm.tools.length; i++){
			var tool = new webIm.tools[i](this);
			this.tools.push(tool);
			toolDiv.appendChild(tool.init());
		}
		dom.newNode('div', {'class':'clear'}, toolDiv);
	},
	
	appendSendBox: function(){
		var sendBoxDiv = dom.newNode('div', {'class':'sendbox_div'}, this.chatDiv);
		this.sendBox = dom.newNode('textarea', {'class':'sendbox'}, sendBoxDiv);
	},

	appendButtonBar: function(){
		var buttonDiv = dom.newNode('div', {'class':'bg button_div'}, this.chatDiv);
		var closeButton = dom.newNode('input', {'type':'button', 'value':' 关 闭 ', 'class':'button'}, buttonDiv);
		var sendButton = dom.newNode('input', {'type':'button', 'value':' 发 送 ', 'class':'button'}, buttonDiv);
		var smallButton = dom.newNode('input', {'type':'button', 'value':'↓', 'class':'small_button'}, buttonDiv);
		dom.roleMouseOver(sendButton, 'button_over');
		dom.roleMouseOver(closeButton, 'button_over');
		dom.roleMouseOver(smallButton, 'small_button_over');
		eve.observe(closeButton, 'click', this.chatWindow.closeWindow, this.chatWindow);
		eve.observe(sendButton, 'click', this.sendMessage, this);
		eve.observe(smallButton, 'click', this.showSendMethod, this);
	},
	
	showErr: function(str){
		alert(str); //todo
	}
};

function imGroupChat(group){
	this.chatWith = group; //this.chatWith为聊天对象 
	this.apps = []; //窗口顶部的功能应用
	this.tools = []; //窗口中部的小工具
	this.userStyle = {}; //用户自定义样式
}

objectExtend(imGroupChat, imChat, {
	init: function(){
		this.groupDiv = dom.newNode('div', {'class':'group_buddies'});
		this.chatDiv = dom.newNode('td', {'vAlign':'top'});
		this.userCount = dom.newNode('span');
		var chatTable = dom.makeHtml(
			['table', {'class':webIm.imCssNameSpace, 'width':'100%', 'cellPadding':'0', 'cellSpacing':'0'}, 
				['tbody', {}, 
					['tr', {}, this.chatDiv,
						['td', {'width':150, 'class':'bg', 'vAlign':'top'},
						['div', {'class':'group_list'}, ['div', {'class':'group_bar'}, '参与者(', this.userCount, ')'], this.groupDiv]]
					]
				]
			]);
		this.appendAppBar();
		this.appendMessageDiv();
		this.appendToolBar();
		this.appendSendBox();
		this.chatWindow = new publicWindow(chatTable, this.chatWith.nickName, webIm.chatWidth + 150);
		this.chatWindow.minHeight = 200;
		this.chatWindow.minWidth = webIm.chatWidth + 50;
		this.appendButtonBar();
		this.chatWindow.cssNameSpace = webIm.windowCssNameSpace; //风格
		this.chatWindow.reHeight = this.reHeight.bind(this);
		this.chatWindow.closeCallBack = this.closeCallBack.bind(this); //设置关闭窗口时的回调函数
		this.chatWindow.init();
		this.getGroupBuddies();
		eve.observe(this.chatWindow.windowDiv, 'mousedown', this.closeCurrentTool, this); //点击messageDiv, fontDiv, sendBox, buttonDiv时,关闭正打开的tool
		eve.observe(this.sendBox, 'keydown', this.checkKeyCode, this);
		if (browser.ie){ //IE浏览器需要每次记录光标的位置.
			this.rang = document.selection.createRange();
			eve.observe(this.sendBox, 'keyup', this.getRang, this);
			eve.observe(this.sendBox, 'click', this.getRang, this);
		}
		this.messageDiv.style.height ='200px'; //聊天窗口默认高度
		this.showMessagePool(); //加载未显示的聊天记录
		this.sendBox.focus();
	},
	
	getGroupBuddies: function(){ //获取群用户
		this.groupDiv.innerHTML = '<br/><br/><br/>加载中.请稍候...<br/><br/><br/>';
		ajax.get('getuser.php?action=getgroupuser&groupname=' + this.nickName, this.listBuddies.bind(this));	
	},
	
	listBuddies: function(re){
		this.groupDiv.innerHTML = '';
		var users = parseJson(re);
		for (var i = users.length - 1; i >= 0; i--){
			var guser = new groupUser(users[i]);
			guser.init();
			this.groupDiv.appendChild(guser.buddyDiv);
		}
		this.setRightDivHeight();
		this.userCount.innerHTML = users.length;
	},

	packMessage: function(jsonStr){
		return 'C|' + this.chatWith.nickName + '|'+jsonStr;
	},

	reHeight: function(my){
		var msgDivHeight = parseInt(this.messageDiv.style.height) + my;
		var groupDivHeight = parseInt(this.groupDiv.style.height) + my;
		this.messageDiv.style.height = msgDivHeight + 'px';
		this.groupDiv.style.height = groupDivHeight + 'px';

	},

	setRightDivHeight: function(){
		this.groupDiv.style.height = this.messageDiv.offsetHeight + this.sendBox.parentNode.offsetHeight + this.messageDiv.nextSibling.offsetHeight + this.sendBox.parentNode.nextSibling.offsetHeight - this.groupDiv.previousSibling.offsetHeight - 2 + 'px'; //-1是自己的border
	}
});
function makeChatTime(){
	var date = new Date();
	return (date.getYear() + ((browser.ie) ? 0 : 1900)) + '-' + date.getMonth() + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
}

function filterContent(str){
	var re = new RegExp(im_block_word, 'gi');
	str = str.replace(re, '[屏蔽字符]');
	return str;
}

function decodeHtml(str){
	str = str.replace(/</g, '&lt;');
	str = str.replace(/>/g, '&gt;');
	str = str.replace(/"/g, '&quot;');
	if (/\[emote=\d+\.gif\]/.test(str))	str = str.replace(/\[emote=(\d+\.gif)\]/g,'<img src="icon/emotion/$1" alt="表情"/>');
	str = str.replace(/\r?\n/g, '<br/>');
	return str;
}

function encodeHtml(str){
	str = str.replace(/\\/g, '\\\\');
	return str;
}

function makeAppIcon(cssName){
	var appIcon = dom.makeHtml(['div', {'class':'app_bg'}, ['div', {'class':'app ' + cssName}]]);
	dom.roleMouseOver(appIcon, 'app_bg_over');
	return appIcon;
}

function makeToolIcon(cssName){
	return dom.newNode('div', {'class': 'tool '+ cssName});
}

function resetList(listObj, seleObj){
	var divs = listObj.getElementsByTagName('div');
	for(var i = divs.length - 1; i >= 0; i--){
		divs[i].className = 'item';
	}
	dom.addClass(seleObj, 'item_sele');
}

function imFont(chatObj){
	this.chatObj = chatObj;
	this.fontPanel = false; //样式面板
	this.fontList = false; //字体列表
	this.sizeList = false; //字号列表
	this.colorList = false; //颜色列表
}
imFont.prototype = {
	init: function(){
		this.fontIcon = makeToolIcon('tool_font');
		eve.observe(this.fontIcon, 'click', this.openFontPanel, this);
		return this.fontIcon;
	},
	
	openFontPanel: function(){
		if (false == this.fontPanel){
			this.fontPanel = this.makeFontPanel();
			dom.roleShow(this.fontIcon, this.fontPanel, true);
		}
		var pos = getPosition(this.fontIcon, this.chatObj.chatWindow.windowDiv);
		this.fontPanel.style.bottom = this.chatObj.chatWindow.windowDiv.offsetHeight - pos[0] + 1 + 'px';
		this.fontPanel.style.left = pos[1] - 4 + 'px';
	},
	
	makeFontPanel: function(){
		var panelInDiv = dom.newNode('div',{'class':'panel_div'}, this.chatObj.chatDiv);
		var panelDiv = dom.newNode('div', {'class':'font_panel bg'}, panelInDiv);
		var fontList = dom.makeHtml(['div', {'class':'list'}, '字 体']);
		var sizeList = dom.makeHtml(['div', {'class':'list'}, '字 号']);
		panelDiv.appendChild(fontList);
		panelDiv.appendChild(sizeList);
		var boldDiv = dom.newNode('div', {'class':'bold'}, panelDiv);
		boldDiv.styleProperty = 'fontWeight';
		boldDiv.styleValue = 'bold';
		boldDiv.cancelValue = 'normal';
		var italicDiv = dom.newNode('div', {'class':'italic'}, panelDiv);
		italicDiv.styleProperty = 'fontStyle';
		italicDiv.styleValue = 'italic';
		italicDiv.cancelValue = 'normal';
		var underlineDiv = dom.newNode('div', {'class':'underline'}, panelDiv);
		underlineDiv.styleProperty = 'textDecoration';
		underlineDiv.styleValue = 'underline';
		underlineDiv.cancelValue = 'none';
		var colorDiv = dom.newNode('div', {'class':'color'}, panelDiv);
		dom.newNode('div', {'class':'clear'}, panelDiv);
		eve.observe(fontList, 'click', this.showFontList, this);
		eve.observe(sizeList, 'click', this.showSizeList, this);
		eve.observe(boldDiv, 'click', this.changeStyle, this);
		eve.observe(italicDiv, 'click', this.changeStyle, this);
		eve.observe(underlineDiv, 'click', this.changeStyle, this);
		eve.observe(colorDiv, 'click', this.showColorList, this);
		return panelInDiv;
	},
	
	changeFont: function(e){
		var obj = e.srcElement || e.target;
		this.chatObj.sendBox.style.fontFamily = obj.innerHTML;
		this.chatObj.userStyle['fontFamily'] = obj.innerHTML;
		if ('宋体' == obj.innerHTML)	delete(this.chatObj.userStyle['fontFamily']);
		resetList(this.fontList, obj);
		this.chatObj.closeCurrentTool();
	},

	showFontList: function(e){
		var obj = e.srcElement || e.target; //事件源
		if (false == this.fontList)	this.fontList = this.createFontList();
		this.chatObj.showTool(this.fontList, obj, 0); //0表示放在在事件源的下边
	},

	createFontList:function(){
		var fonts = ['宋体','黑体','楷体_GB2312','隶书','Arial','Impact','Courier New'];
		var listDiv = dom.newNode('div', {'class':'option_list fontlist hide'}, this.chatObj.chatDiv);
		for(var i = 0;i < fonts.length; i++){
			var div = dom.makeHtml(['div', {'class':'item'}, fonts[i]]);
			div.style.fontFamily = fonts[i];
			eve.observe(div, 'mousedown', this.changeFont, this);
			dom.roleMouseOver(div, 'item_over');
			listDiv.appendChild(div);
		}
		dom.addClass(listDiv.firstChild, 'item_sele');
		return listDiv;
	},
	
	showSizeList: function(e){
		var obj = e.srcElement || e.target;
		if (false == this.sizeList)	this.sizeList = this.createSizeList();
		this.chatObj.showTool(this.sizeList, obj ,0); //0表示放在在事件源的下边
	},

	createSizeList: function(){
		var sizes = ['12px', '14px', '16px', '18px', '20px', '22px', '24px'];
		var listDiv = dom.newNode('div', {'class':'option_list sizelist hide'}, this.chatObj.chatDiv);
		for(var i = 0; i < sizes.length; i++){
			var div = dom.makeHtml(['div', {'class':'item'}, sizes[i]]);
			div.style.fontSize = sizes[i];
			eve.observe(div, 'mousedown', this.changeSize, this);
			dom.roleMouseOver(div, 'item_over');
			listDiv.appendChild(div);
		}
		dom.addClass(listDiv.firstChild, 'item_sele');
		return listDiv;
	},

	showColorList: function(e){
		var obj = e.srcElement || e.target;
		if (false == this.colorList)	this.colorList = this.createColrList();
		this.chatObj.showTool(this.colorList, obj, 0); //0表示放在在事件源的下边
	},

	createColrList: function(){
		var colors = ['000000','993300','333300','003300','003366','333399','333333','800000','FF6600','808000','808080','008080','FF0000','FF9900','99CC00','800080','00FF00','FF00FF','FFCC00','FFFF00','00CCFF','FF99CC','0000FF','FB015F'];
		var colorList = dom.newNode('div', {'class':'colordiv'}, this.chatObj.chatDiv);
		for (var i = 0; i<colors.length; i++){
			var div = dom.makeHtml(['div', {}, '&nbsp;']);
			div.style.backgroundColor = '#' + colors[i];
			eve.observe(div, 'mousedown', this.changeColor, this);
			colorList.appendChild(div);
		}
		colorList.firstChild.className = 'sele'; //默认
		return colorList;
	},

	changeColor: function(e){
		var obj = e.srcElement || e.target;
		this.chatObj.sendBox.style.color = obj.style.backgroundColor;
		this.chatObj.userStyle['color'] = obj.style.backgroundColor;
		if (!obj.previousSibling)	delete(this.chatObj.userStyle['color']); //如果点击第一个(黑色), 取消该属性
		var divs = this.colorList.getElementsByTagName('div');
		for(var i = divs.length - 1; i >= 0; i--){
			if ('sele' == divs[i].className){
				divs[i].className = null;
				break;
			}
		}
		dom.addClass(obj, 'sele');
		this.chatObj.closeCurrentTool();
	},
	
	changeSize: function(e){
		var obj = e.srcElement||e.target;
		this.chatObj.sendBox.style.fontSize = obj.innerHTML;
		this.chatObj.userStyle['fontSize'] = obj.innerHTML;
		if ('12px' == obj.innerHTML)	delete(this.chatObj.userStyle['fontSize']); //如果是12px,取消该自定义样式
		resetList(this.sizeList, obj);
		this.chatObj.closeCurrentTool();
	},

	changeStyle: function(e){
		var obj = e.srcElement || e.target;
		if (/_use/.test(obj.className)){
			//debug(obj.cancelValue);
			this.chatObj.sendBox.style[obj.styleProperty] = obj.cancelValue;
			delete(this.chatObj.userStyle[obj.styleProperty]);
			obj.className = obj.className.replace('_use', '');
		}else{
			this.chatObj.sendBox.style[obj.styleProperty] = obj.styleValue;
			this.chatObj.userStyle[obj.styleProperty] = obj.styleValue;
			obj.className += ' '+obj.className+'_use';
		}
		this.chatObj.sendBox.focus();
	}
};

function imEmote(chatObj){
	this.chatObj = chatObj;
}
imEmote.prototype = {
	emoteList: false,
	init: function(){
		this.emoteIcon = makeToolIcon('tool_emotion');
		eve.observe(this.emoteIcon, 'click', this.showEmoteList, this);
		return this.emoteIcon;
	},

	showEmoteList: function(e){
		var obj = e.srcElement||e.target;
		if (false == this.emoteList)	this.emoteList = this.createEmoteList();
		this.chatObj.showTool(this.emoteList, obj, 1); //1表示放在事件源上边
	},
	
	createEmoteList: function(){
		var emoteList = dom.newNode('div', {'class':'emotion'}, this.chatObj.chatDiv);
		for (var i = 0; i < 24; i++){
			var div = dom.makeHtml(['div', {}, ['img',{'src':'icon/emotion/'+i+'_s.gif'}]]);
			dom.roleMouseOver(div, 'over');
			eve.observe(div, 'mousedown', this.insertEmote, this);
			emoteList.appendChild(div);
		}
		return emoteList;
	},
	
	insertEmote: function(e){
		var obj = e.srcElement || e.target;
		if ('img' != obj.tagName.toLowerCase())	return;
		this.chatObj.closeCurrentTool();
		var emoteSrc = obj.src.replace('_s', '');
		emoteSrc = emoteSrc.split('/');
		this.chatObj.insertValue('[emote=' + emoteSrc[emoteSrc.length - 1] + ']');
	}
};

function imLog(chatObj){
	this.chatObj = chatObj;
}
imLog.prototype = {
	init: function(){
		this.logIcon = makeAppIcon('app_log');
		eve.observe(this.logIcon, 'click', this.showLog, this);
		return this.logIcon;
	},
	
	showLog: function(){
		alert('查看聊天记录');
	}
};

function imCamera(chatObj){
	this.chatObj = chatObj;
}
imCamera.prototype = {
	init: function(){
		this.camIcon = makeAppIcon('app_cam');
		eve.observe(this.camIcon, 'click', this.showCamera, this);
		return this.camIcon;
	},
	
	showCamera: function(){
		alert('打开视频聊天');
	}
};

function imInfo(chatObj){
	this.chatObj = chatObj;
}
imInfo.prototype = {
	init: function(){
		this.infoIcon = makeAppIcon('app_info');
		eve.observe(this.infoIcon, 'click', this.showInfo, this);
		return this.infoIcon;
	},

	showInfo: function(){
		alert('查看infomation');
	}
};

var im_block_word =
//(一)	政治敏感人物名称：
//国内政要人物：
"毛泽东|周恩来|刘少奇|朱德|彭德怀|林彪|刘伯承|陈毅|贺龙|聂荣臻|徐向前|罗荣桓|叶剑英|李大钊|陈独秀|孙中山|孙文|孙逸仙|邓小平|陈云|江泽民|李鹏|朱镕基|李瑞环|尉健行|李岚清|胡锦涛|罗干|温家宝|吴邦国|曾庆红|贾庆林|黄菊|吴官正|李长春|吴仪|回良玉|曾培炎|周永康|曹刚川|唐家璇|华建敏|陈至立|陈良宇|张德江|张立昌|俞正声|王乐泉|刘云山|王刚|王兆国|刘淇|贺国强|郭伯雄|胡耀邦|王乐泉|王兆国|周永康|李登辉|连战|陈水扁|宋楚瑜|吕秀莲|郁慕明|蒋介石|蒋中正|蒋经国|马英九|"
//国外政要人物：
+"布什|布莱尔|小泉|纯一郎|萨马兰奇|安南|阿拉法特|普京|默克尔|克林顿|里根|尼克松|林肯|杜鲁门|赫鲁晓夫|列宁|斯大林|马克思|恩格斯|金正日|金日成|萨达姆|胡志明|西哈努克|希拉克|撒切尔|阿罗约|曼德拉|卡斯特罗|富兰克林|华盛顿|艾森豪威尔|拿破仑|亚历山大|路易|拉姆斯菲尔德|劳拉|鲍威尔|"
//敏感人物名称或代号：
+"本拉登|奥马尔|柴玲|达赖喇嘛|江青|张春桥|姚文元|王洪文|东条英机|希特勒|墨索里尼|冈村秀树|冈村宁次|高丽朴|赵紫阳|王丹|沃尔开西|李洪志|李大师|赖昌星|马加爵|班禅|额尔德尼|山本五十六|阿扁|"
//其他著名人物：
+"鲁迅|莎士比亚|爱因斯坦|牛顿|哥白尼|哥伦布|达芬奇|米开朗基罗|毕加索|梵高|海明威|斯蒂芬霍金|"
//(二)	涉嫌反动、恐怖主义敏感词汇：
+"六四|六四运动|美国之音|密宗|民国|民进党|民运|民主|民主潮|摩门教|纳粹|南华早报|南蛮|明慧网|起义|亲民党|瘸腿帮|人民报|法轮功|法轮大法|打倒共产党|台独万岁|圣战|示威|台独|台独分子|台联|台湾民国|台湾岛国|台湾独立|太子党|天安门事件|屠杀|小泉|新党|新疆独立|新疆分裂|新疆国|疆独|西藏独立|西藏分裂|西藏国|藏独|藏青会|藏妇会|学潮|学运|一党专政|一中一台|两个中国|一贯道|游行|圆满|造反|真善忍|镇压|政变|政治|政治反对派|政治犯|中共|共产党|反党|反共|政府|民主党|中国之春|转法轮|自焚|共党|共匪|苏家屯|基地组织|塔利班|东亚病夫|支那|高治联|高自联|"
//(三)	国家安全：
+"核工业基地|核武器|铀|原子弹|氢弹|导弹|核潜艇|大参考|小参考|国内动态清样|"
//(四)	宗教：
+"道教|多维|佛教|佛祖|释迦牟尼|如来|阿弥陀佛|观世音|普贤|文殊|地藏|河殇|回教|密宗|摩门教|穆罕默德|穆斯林|升天|圣母|圣战|耶和华|耶稣|伊斯兰|真主安拉|白莲教|天主教|基督教|东正教|"
//(五)	邪教迷信
+"大法|法轮|法轮功|瘸腿帮|真理教|真善忍|转法轮|自焚|走向圆满|黄大仙|风水|跳大神|神汉|神婆|真理教|大卫教|阎王|黑白无常|牛头马面|"
//(六)	煽动民族仇恨：
+"藏独|高丽棒子|回回|疆独|蒙古鞑子|台独|台独分子|台联|台湾民国|西藏独立|新疆独立|南蛮|老毛子|"
//(七)	犯罪行为：
+"谋杀|杀人|吸毒|贩毒|赌博|拐卖|走私|卖淫|造反|监狱|强奸|轮奸|抢劫|先奸后杀|"
//(八)	赌博行为敏感词汇：
+"下注|押大|押小|抽头|坐庄|赌马|赌球|筹码|老虎机|轮盘赌|"
//(九)	毒品敏感词汇：
+"安非他命|大麻|可卡因|海洛因|冰毒|摇头丸|杜冷丁|鸦片|罂粟|迷幻药|白粉|嗑药|吸毒|"
//(十)	性名词：
+"AIDS|aids|Aids|DICK|dick|Dick|penis|sex|SM|屙|爱滋|淋病|梅毒|爱液|屄|逼|臭机八|臭鸡巴|吹喇叭|吹箫|催情药|屌|肛交|肛门|龟头|黄色|机八|机巴|鸡八|鸡巴|机掰|机巴|鸡叭|鸡鸡|鸡掰|鸡奸|妓女|奸|茎|精液|精子|尻|口交|滥交|乱交|轮奸|卖淫|屁眼|嫖娼|强奸|强奸犯|情色|肉棒|乳房|乳峰|乳交|乳头|乳晕|三陪|色情|射精|手淫|威而钢|威而柔|伟哥|性高潮|性交|性虐|性欲|穴|颜射|阳物|一夜情|阴部|阴唇|阴道|阴蒂|阴核|阴户|阴茎|阴门|淫|淫秽|淫乱|淫水|淫娃|淫液|淫汁|淫穴|淫洞|援交妹|做爱|梦遗|阳痿|早泄|奸淫|性欲|性交|"
//(十一)	侮辱性语言：
+"Bitch|bt|cao|kao|NMD|NND|sb|shit|SHIT|SUCK|Suck|tmd|TMD|tnnd|K他命|白痴|笨蛋|屄|逼|变态|婊子|操|操她妈|操妳妈|操你|操你妈|操他妈|草你|肏|册那|侧那|测拿|插|蠢猪|荡妇|发骚|废物|干她妈|干妳|干妳娘|干你|干你妈|干你妈B|干你妈b|干你妈逼|干你娘|干他妈|狗娘养的|滚|鸡奸|贱货|贱人|靠|烂人|老母|老土|妈比|妈的|马的|妳老母的|妳娘的|你妈逼|破鞋|仆街|去她妈|去妳的|去妳妈|去你的|去你妈|去死|去他妈|^日+[.,!#！，。]*$|日你|赛她娘|赛妳娘|赛你娘|赛他娘|骚货|傻B|傻比|傻子|上妳|上你|神经病|屎|屎妳娘|屎你娘|他妈的|王八蛋|我操|我日|乡巴佬|猪猡|屙|干|尿|掯|屌|操|骑你|湿了|操你|操他|操她|骑你|骑他|骑她|欠骑|欠人骑|来爽我|来插我|干你|干他|干她|干死|干爆|干机|FUCK|机叭|臭鸡|臭机|烂鸟|览叫|阳具|肉棒|肉壶|奶子|摸咪咪|SUCK|PENIS|BITCH|TMD|BLOW|JOB|KISS|MY|ASS|SHIT|干鸡|干入|小穴|强奸|插你|插你|爽你|爽你|干干|干X|我操|他干|干它|干牠|干您|干汝|干林|操林|干尼|操尼|我咧干|干勒|干我|干到|干啦|干爽|欠干|狗干|我干|来干|轮干|轮流干|干一干|援交|骑你|我操|轮奸|鸡奸|奸暴|再奸|我奸|奸你|奸你|奸他|奸她|奸一奸|淫水|淫湿|鸡歪|仆街|臭西|尻|吊|遗精|烂逼|大血比|叼你妈|靠你妈|草你|干你|日你|插你|奸你|戳你|逼你老母|挨球|我日你|草拟妈|卖逼|狗操卖逼|奸淫|日死|奶子|阴茎|奶娘|他娘|她娘|骚B|你妈了妹|逼毛|插你妈|叼你|渣波波|嫩b|"
//(十二)	仿冒系统管理员：
+"ADMIN|Admin|admin|Administrator|administrator|管理|管里|管理员|服务管理|服务器|活动管理员|官方|维护|系统|系统公告|审查|巡查|监督|监管|系統|系統公告|"
//(十三)	仿冒游戏主管：
+"game|master|GAMEMASTER|GameMaster|GM|游戏管理员|"
//(十四)	仿冒客户服务员：
+"Client|Server|CS|Cs|cs|cS|KEFU|kefu|Kefu|KeFu|助理|客户服务|客服|服务天使|"
//(十五)	仿冒游戏测试人员：
+"辅助程序|"
//(十六)	仿冒游戏运营人员：
+"运营|运营者|运营组|运营商|运营长|运营官|运营人|"
//(十七)	违法游戏行为：
+"私服|私人服务器|外挂";